#include "sys.h"
#include "dial.h"

pthread_mutex_t SpeedTest_lock = PTHREAD_MUTEX_INITIALIZER;
int SpeedTest_Flag = 0;

void* dial(do_fun fun, void* arg_in)
{
    pthread_t thid;
    void* arg_out;
    dial_arg_t* dial_arg = (dial_arg_t*)arg_in;

    if (dial_arg->bridge_mode) {
        pthread_create(&thid, NULL, fun, arg_in);
        pthread_join(thid, &arg_out);
    } else {
        arg_out = fun(arg_in);
    }
    assert(arg_out != NULL);
    return arg_out;
}

void* dial_ping(void* arg)
{
    return dial(do_ping, arg);
}

void* dial_tcp(void* arg)
{
    return dial(do_tcp, arg);
}

void* dial_dns(void* arg)
{
    return dial(do_dns, arg);
}

void* dial_http(void* arg)
{
    return dial(do_http, arg);
}

void* dial_http_light(void* arg)
{
    return dial(do_http_light, arg);
}

void* dial_http_download(void* arg)
{
    return dial(do_http_download, arg);
}
void* dial_http_upload(void* arg)
{
    return dial(do_http_upload, arg);
}
void* dial_traceroute(void* arg)
{
    return dial(do_traceroute, arg);
}

void* dial_tcpping(void* arg)
{
    return dial(do_tcpping, arg);
}